﻿using System;
using System.Collections.Generic;
using System.Text;

using WebKit;
using System.Windows.Forms;
using System.Threading;

namespace Crawler_v1.service.impl
{
    class WebKitGooutCrawler : IGooutCrawler
    {
        protected string baseUrl = "http://fec.mofcom.gov.cn/article/fwydyl/";
        private WebKitBrowser webKitBrowser1;

        delegate void GetListDone();
        event GetListDone mGetListDone;

        
        private GetListDone getListDone;


        event EventHandler MyDocumentCompleted;

        public WebKitGooutCrawler()
        {
            this.webKitBrowser1 = new WebKitBrowser();
            webKitBrowser1.Navigated+= (s, e) =>
            {
                //DocumentCompleted 
                invokeGetListDone();
            };
        }

        public void getList(Action<object> completed)
        {
            //事件增加方法
            MyDocumentCompleted += (s,e) =>
            {
                var thread = new Thread(new ParameterizedThreadStart(completed));
                thread.Start("");//此线程用于通知数据已经获取完毕,执行线程将往下执行.
            };
        }

        public void getContent(string url,Action<object> completed)
        {
            //事件增加方法
            MyDocumentCompleted += (s, e) =>
            {
                var thread = new Thread(new ParameterizedThreadStart(completed));
                thread.Start("");//此线程用于通知数据已经获取完毕,执行线程将往下执行.
            };
        }

        private void invokeGetListDone()
        {
            mGetListDone();
        }

    }
}
